const { defineConfig } = require('@vue/cli-service')
// const path = require('path')
// webpack.config.js
//element自动引入
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const path = require('path')
const Icons = require('unplugin-icons/webpack')
const IconsResolver = require('unplugin-icons/resolver')
// const { defineConfig } = require('@vue/cli-service')
// const path = require('path')
// const Icons = require('unplugin-icons/webpack')
// const IconResolver = require('unplugin-icons/resolver')
// const Components = require('unplugin-vue-components/webpack')
const pathSrc = path.resolve(__dirname, 'src')

module.exports = defineConfig({
  transpileDependencies: true,
  // 打包输出目录 第一种配置方式：cli提供的属性
  // outputDir: "./build",
  //第二种配置方式： 和webpack属性完全一致，最后会进行合并
  devServer: {
    proxy: {
      '^/api': {
        target: 'http://152.136.185.210:5000',
        pathRewrite: {
          '^/api': ''
        },
        chengeOrigin: true
      }
    }
  },
  configureWebpack: {
    resolve: {
      alias: {
        components: '@/components'
      }
    },
    plugins: [
      AutoImport({
        // 自动导入 Element Plus 相关函数
        resolvers: [
          ElementPlusResolver(),
          // Auto import icon components
          // 自动导入图标组件
          IconsResolver({
            prefix: 'Icon'
          })
        ],
        dts: path.resolve(pathSrc, 'auto-imports.d.ts')
      }),
      Components({
        resolvers: [
          // Auto register icon components
          // 自动注册图标组件
          IconsResolver({
            enabledCollections: ['ep']
          }),
          ElementPlusResolver()
        ],
        dts: path.resolve(pathSrc, 'components.d.ts')
      }),
      Icons({
        autoInstall: true
      })
    ]
  }
  // configureWebpack: (config) => {
  //   config.resolve.alias = {
  //     '@': path.resolve(__dirname, 'src'),
  //     components: '@/components'
  //   }
  // },
  //配置方式三： 链式编程
  // chainWebpack: (config) => {
  //   config.resolve.alias
  //     .set('@', path.resolve(__dirname, 'src'))
  //     .set('components', '@/components')
  // }
})
